/**
 * 
 */
package com.jrh.dal;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jrh.domain.common.Page;
import com.jrh.domain.entity.ProductRef;

/**
 * @author IBM 2012-7-18 下午8:29:32
 */
public class ProductRefDao extends BaseDao<ProductRef> {

    {
        namespace = "jrh.single.product.ref";
    }

    @SuppressWarnings("unchecked")
    public Page<ProductRef> getProductAdPage(Long brandId, String refType, Integer start, Integer pageSize) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("refType", refType);
        map.put("brandId", brandId);
        map.put("start", start);
        map.put("pageSize", pageSize);
        List<ProductRef> productRefList = (List<ProductRef>) sqlMapClientTemplate.queryForList(namespace
                                                                                               + ".listProductAd", map);
        Integer count = (Integer) sqlMapClientTemplate.queryForObject(namespace + ".countProductAd", map);
        return new Page<ProductRef>(productRefList, start, pageSize, count);
    }

    @SuppressWarnings("unchecked")
    public Page<ProductRef> getProductGroupPage(Long brandId, String refType, Integer start, Integer pageSize) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("refType", refType);
        map.put("brandId", brandId);
        map.put("start", start);
        map.put("pageSize", pageSize);
        List<ProductRef> productRefList = (List<ProductRef>) sqlMapClientTemplate.queryForList(namespace
                                                                                                       + ".listProductGroup",
                                                                                               map);
        Integer count = (Integer) sqlMapClientTemplate.queryForObject(namespace + ".countProductGroup", map);
        return new Page<ProductRef>(productRefList, start, pageSize, count);
    }

    public int deleteProductAd(Long productAdId) {
        return sqlMapClientTemplate.delete(namespace + ".deleteProductAd", productAdId);
    }

    public int deleteProductGroup(Long productGroupId) {
        return sqlMapClientTemplate.delete(namespace + ".deleteProductGroup", productGroupId);
    }

    public int deleteProductRef(Map<String, Object> map) {
        return sqlMapClientTemplate.delete(namespace + ".deleteProductRef", map);
    }

    public List<ProductRef> listSameTypeProduct(Long productId, String refType, int pageSize) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("refType", refType);
        map.put("productId", productId);
        map.put("pageSize", pageSize);
        return (List<ProductRef>) sqlMapClientTemplate.queryForList(namespace + ".listSameTypeProduct", map);
    }

    public ProductRef getProductAd(Long productId, String refType) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("refType", refType);
        map.put("productId", productId);
        return (ProductRef) sqlMapClientTemplate.queryForObject(namespace + ".getProductAd", map);
    }

    public void createProductAd(ProductRef productRef) {
        sqlMapClientTemplate.insert(namespace + "." + "createProductAd", productRef);
    }

    public void createProductGroup(ProductRef productRef) {
        sqlMapClientTemplate.insert(namespace + "." + "createProductGroup", productRef);
    }

}
